<?php
    session_start();

    if (!isset($_SESSION['is_logged_in'])) {
        header("Location:../index.php");
        die();
    }
    
    ini_set('display_errors',"1");
    include("conexion.php");
    
    $strSQL = $_POST["strSQL"];
    $cantCols = $_POST["cantCols"]; 
	
    $conn = new mysqli($dbhost, $dbuser, $dbpass, $db) or die("Problemas al conectar con la BD");
	
	if (!($tabla = $conn->query($strSQL))) {
		$strSalida = "Error al realizar la consulta.<br>";
		$strSalida.= $con->error;
	}
	else {
		$strSalida = "";
		
		if ($tabla->num_rows > 0) {
			while ($fila = $tabla->fetch_array()) {
				for ($I = 0; $I < $cantCols; $I++) {
					if ($I == 0)
						$strSalida.= $fila[$I];
					else
						if ($I == $cantCols - 1)
							$strSalida.= "||".$fila[$I]."##";
						else
							$strSalida.= "||".$fila[$I];
				}
			}
			
			$tabla->free();
		}
	}
		
    $conn->close();
	echo $strSalida;
?>